package com.android.wheretogo.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

public class JsonContent {
	 public static String getContent(HttpUriRequest request) throws Exception{
    	 StringBuffer sb = new StringBuffer();
    	 HttpClient client = new DefaultHttpClient();
    	 HttpParams httpParams = client.getParams();
    	 
    	 HttpConnectionParams.setConnectionTimeout(httpParams,30000);
    	 HttpConnectionParams.setSoTimeout(httpParams, 50000);
    	 HttpResponse response = client.execute(request);
    	 HttpEntity entity = response.getEntity();
    	 if(entity != null){
    		 BufferedReader reader = new BufferedReader(
    				 new InputStreamReader(entity.getContent(),
    						 "UTF-8"),8192);
    		 
    		 String line = null;
    		 while((line = reader.readLine()) != null){
    			 sb.append(line+"\n");
    		 }
    		 reader.close();
    	 }
    	 return sb.toString();
	}
}
